<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>添加品牌</title>
</head>
<body>
<div id="app">
    <h3>添加品牌</h3>
    <form action="" method="post">
        品牌名称：<input id="brandName" v-model="brand.brandName" name="brandName"><br>
        企业名称：<input id="companyName" v-model="brand.companyName" name="companyName"><br>
        排序：<input id="ordered" v-model="brand.ordered" name="ordered"><br>
        描述信息：<textarea rows="5" cols="20" id="description" v-model="brand.description" name="description"></textarea><br>
        状态：
        <input type="radio" name="status" v-model="brand.status" value="0">禁用
        <input type="radio" name="status" v-model="brand.status" value="1">启用<br>

        <input type="button" id="btn" @click="submitForm" value="提交">
    </form>
</div>

<script src="js/axios-0.18.0.js"></script>
<script src="js/vue.js"></script>
<script>
    // document.getElementById("btn").onclick = function (){
    //     // 将表单数据转化为json
    //     var formData = {
    //         brandName:"",
    //         companyName:"",
    //         ordered:"",
    //         description:"",
    //         status:"",
    //     };
    //     // 获取表单数据并设置数据
    //     let brandName = document.getElementById("brandName").value;
    //     formData.brandName = brandName;
    //     let companyName = document.getElementById("companyName").value;
    //     formData.companyName = companyName;
    //     let ordered = document.getElementById("ordered").value;
    //     formData.ordered = ordered;
    //     let description = document.getElementById("description").value;
    //     formData.description = description;
    //     // 选项卡获取到了一些数据
    //     let status = document.getElementsByName("status");
    //     for(let i = 0;i < status.length;i++){
    //         if(status[i].checked){
    //             formData.status = status[i].value;
    //         }
    //     }
    //     // 发送axios请求
    //     axios({
    //         method:"post",
    //         url:"http://localhost:8080/brand-demo2/addServlet",
    //         data:formData
    //     }).then(function (resp) {
    //         // 判断响应数据是否为 success
    //         if(resp.data == "success"){
    //             location.href = "http://localhost:8080/brand-demo2/brand.html";
    //         }
    //     })
    // }

    new Vue({
        el:"#app",
        data(){
            return {
                // 在数据域里面先放一个空对象
                brand:{}
            }
        },
        methods:{
            submitForm(){
                var _this = this;
                axios({
                    method:"post",
                    url:"http://localhost:8080/brand-demo2/addServlet",
                    data:_this.brand
                }).then(function (resp){
                    if(resp.data == "success"){
                        location.href = "http://localhost:8080/brand-demo2/brand.html";
                    }
                })
            }
        }
    })
</script>
</body>
</html>